package cn.mothin.action.system;

import org.springframework.beans.factory.annotation.Autowired;

import cn.mothin.frame.core.annotation.Module;
import cn.mothin.frame.core.annotation.NeedLogon;
import cn.mothin.frame.core.annotation.NeedModule;
import cn.mothin.frame.core.annotation.NeedPermission;
import cn.mothin.frame.core.annotation.NeedPermissionAs;
import cn.mothin.frame.core.annotation.NeedPermissionTemplate;
import cn.mothin.frame.core.annotation.OperationLink;
import cn.mothin.frame.core.base.BaseAction;
import cn.mothin.service.system.UserService;
import cn.mothin.vo.system.UserForm;

@SuppressWarnings("serial")
@Module(id = "54125f4a2ae3e65d6895254b", name = "用户管理")
public class UserAction extends BaseAction {
    private UserForm userForm = new UserForm();
    @Autowired
    private UserService userService;

    @Override
    public Object getModel() {
        return userForm;
    }
    
    @NeedModule
    public String execute() {
        return SUCCESS;
    }

    /**
     * 查询人员列表信息
     * 
     * @return
     */
    @NeedModule
    public String query() {
        return this.renderJson(userService.query(userForm));
    }
    
    @NeedLogon
    public String queryUserRole(){
        return renderJson(userService.queryUserRole(userForm));
    }

    /**
     * 添加新人员页面
     * 
     * @return
     */
    @OperationLink(link = "execute", ordinal = 0)
    @NeedPermissionTemplate(id = "54124b3a2ae3e65d68952548", template = NeedPermissionTemplate.CREATE)
    public String add() {
        return "add";
    }

    /**
     * 保存新人员
     * 
     * @return
     */
    @NeedPermissionAs("add")
    public String saveForAdd() {
        return renderJson(userService.addSystemUser(userForm).toJson());
    }

    /**
     * 查看人员信息
     * 
     * @return
     */
    @OperationLink(link = "execute", ordinal = 0, rowOperation = true)
    @NeedPermissionTemplate(id = "541263b62ae3e65d6895254c", template = NeedPermissionTemplate.DETAIL)
    public String view() {
        userService.queryUser(userForm);
        return "view";
    }

    @OperationLink(link = "execute", ordinal = 1, rowOperation = true)
    @NeedPermissionTemplate(id = "541252a22ae3e65d68952549", template = NeedPermissionTemplate.UPDATE)
    public String update() {
        userService.queryUser(userForm);
        return "update";
    }

    @NeedPermissionAs("update")
    public String saveForUpdate() {
        return renderJson(userService.update(userForm).toJson());
    }

    /**
     * 删除
     * 
     * @return
     */
    @OperationLink(link = "execute", ordinal = 2, rowOperation = true)
    @NeedPermissionTemplate(id = "541255bc2ae3e65d6895254a", template = NeedPermissionTemplate.DELETE)
    public String deleteUser() {
        return renderJson(userService.delete(userForm).toJson());
    }

    /**
     * 重置密码
     * 
     */
    @OperationLink(link = "execute", ordinal = 3, rowOperation = true)
    @NeedPermission(id = "54128c662ae3e65d6895254e", name = "重置密码", ico = "glyphicon glyphicon-repeat")
    public String resetpsw() {
        return renderJson(userService.resetpsw(userForm).toJson());
    }
}
